package com.mfjhss.springcloud.controller;

import com.mfjhss.springcloud.entity.CommonResult;
import com.mfjhss.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
public class OrderController {

    public static final String PAYMENT_URL = "http://localhost:8081";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping (value = "/consumer/payment/create")
    public CommonResult<Payment> create(Payment payment){
        System.out.println("1111111111");
        System.out.println(payment.toString());
        return restTemplate.postForObject(PAYMENT_URL + "/payment/create",payment,CommonResult.class);
    }

    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/"+id,CommonResult.class);
    }

    @GetMapping(value = "/consumer/payment/zipkin")
    public String paymentZipkin(){
        return restTemplate.getForObject(PAYMENT_URL + "/payment/zipkin",String.class);
    }
}
